﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace CMS6Tools.Common.Email
{
    #region abstract EmailTemplate

    public abstract class EmailTemplate : ITextTemplate
    {

        #region Implement ITextTemplate interface

        public abstract string Transform(ITextTemplateExtraData extraData);

        #endregion


        #region public method

        public virtual void GetSubjectAndBody(string content, out string subject, out string body)
        {
            var titleMatch = Regex.Match(content, @"<\s*title\s*>(.*?)<\s*/\s*title\s*>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            if (titleMatch.Success)
            {
                subject = titleMatch.Groups[1].Value;
            }
            else
            {
                subject = string.Empty;
            }
            var bodyMatch = Regex.Match(content, @"<\s*body\s*>(.*?)<\s*/\s*body\s*>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            if (bodyMatch.Success)
            {
                body = bodyMatch.Groups[1].Value;
            }
            else
            {
                body = string.Empty;
            }
        }

        #endregion
    }

    #endregion
}
